<template>

        <div class="goods-list">
            <!-- <router-link :to="'/home/goodsinfo/'+item.comment" class="goods-item" v-for="item in goods" :key="item.Array" >
                <img :src="item.thumbnail" alt="">
                <h1 class="title">{{item.username}}</h1>
                <div class="info">
                    <p class="price">
                        <span class="now">${{item.down}}</span>
                        <span class="old">${{item.comment}}</span>
                    </p>
                    <p class="sell">
                        <span>热卖中</span>
                        <span>剩{{item.forward}}件</span>
                    </p>
                </div>

            </router-link> -->
                  <div class="goods-item" v-for="item in goods" :key="item.Array" @click="goDetail(item.comment)">
                <img :src="item.thumbnail" alt="">
                <h1 class="title">{{item.username}}</h1>
                <div class="info">
                    <p class="price">
                        <span class="now">${{item.down}}</span>
                        <span class="old">${{item.comment}}</span>
                    </p>
                    <p class="sell">
                        <span>热卖中</span>
                        <span>剩{{item.forward}}件</span>
                    </p>
                </div>

            </div>
          <mt-button type="danger" size="large" @click="getmore">加载更多</mt-button>
        </div>

        
 
</template>
<script>
export default {
    data() {
        return {
            goods:[]
        }
    },
    created() {
        this.getGoodsList();
    },
    methods: {
        getGoodsList(){
            this.$http.get("satinGodApi?type=5&page=1").then(result=>{
                 console.log(result.body);
                if(result.body.code===200){
                    this.goods=this.goods.concat(result.body.data);
                    // console.log(result.body);  
                }           
            })
        },
        getmore(){
            this.getGoodsList();
        },
        goDetail(comment){
            
            //区分route和router两个对象，
            //this.$route 是路由参数对象，所有路有中的参数,params,query都属于它
            //this.$router是一个路由导航对象，用它可以方便的时候js代码，实现路由的前进后退跳转到新的url
            // this.$router.push({ name: 'goodsinfo', params: { comment: 'comment' }});
            this.$router.push({path:"/home/goodsinfo/"+comment})
        }
    },
}
</script>
<style lang="less">
.goods-list{
    display: flex;
    flex-wrap:wrap;
    padding: 7px;
    justify-content: space-between;
    .goods-item{
        width: 49%;
        box-shadow: 0 0 10px #ccc;
        margin-bottom: 5px;
        padding: 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 267px;
        img{
            width: 100%;
        }
        h1{
            
            font-size: 18px;
            text-align: left;
        }
        .info{
            background-color: #ccc;
            p{
                margin: 0;
                padding: 5px;
            }
            .price{
                display: flex;
                justify-content: space-around;
                padding-top: 5px;
                .now{
                    color: red;
                    font-size: 17px;
                    font-weight: bold;
                }
                .old{
                    font-size: 13px;
                    padding-right: 50px;
                    text-decoration: line-through;
                }
            }
            .sell{
                display: flex;
                justify-content: space-between;

            }
            
        }
    }
}
</style>
